﻿using Newtonsoft.Json;
using System.Text.RegularExpressions;

namespace 控制台_测试低压详情返回值
{
    internal class Program
    {
        static void Main(string[] args)
        {

            //    string[] testStrings = {
            //    "不能起动(交流接触器不工作)(交流接触器线圈不得电)K2-5-C1",
            //    "不能自锁(功能不全)(K2-5-G1)"
            //};

            //    string pattern = @"K\d+-\d+-[A-Za-z]\d+";

            //    foreach (string input in testStrings)
            //    {
            //        MatchCollection matches = Regex.Matches(input, pattern);
            //        foreach (Match match in matches)
            //        {
            //            if (match.Success)
            //            {
            //                Console.WriteLine(match.Value);
            //            }
            //        }
            //    }

            var input = "[{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":12.0,\"content\":\"主电路缺相(功能不全)(K2-5-G4)\"},{\"score\":0.0,\"content\":\"\"},{\"score\":12.0,\"content\":\"主电路缺相(功能不全)(K2-5-G4)\"},{\"score\":12.0,\"content\":\"主电路缺相(功能不全)(K2-5-G4)\"},{\"score\":4.0,\"content\":\"未按规定装接接地线(电动机外壳未连接地线)(K2-5-E)\"},{\"score\":4.0,\"content\":\"未按规定装接接地线(电动机外壳未连接地线)(K2-5-E)\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":80.0,\"content\":\"不能起动(交流接触器不工作)(交流接触器线圈不得电)K2-5-C1\"},{\"score\":12.0,\"content\":\"不能自锁(功能不全)(K2-5-G1)\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"K2-2-E\"},{\"score\":0.0,\"content\":\"\"}]";
           // input = "[{\"score\":12.0,\"content\":\"主电路缺相(功能不全)(K2-1-G4)\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":0.0,\"content\":\"\"},{\"score\":4.0,\"content\":\"电机旋转方向错误\"}]";
            var details = JsonConvert.DeserializeObject<List<Detail>>(input);

            //List<string> list = new List<string>();
            //bool functionIncompleteAdded = false; // 用于追踪"功能不全"是否已添加

            //foreach (var detail in details)
            //{
            //    if (string.IsNullOrEmpty(detail.content))
            //        continue;

            //    // 检查是否包含"功能不全"且尚未添加过
            //    bool containsFunctionIncomplete = detail.content.Contains("功能不全");
            //    if (containsFunctionIncomplete && !functionIncompleteAdded)
            //    {
            //        string pattern = @"K\d+-\d+-[A-Za-z]\d+";
            //        MatchCollection matches = Regex.Matches(detail.content, pattern);

            //        foreach (Match match in matches)
            //        {
            //            if (match.Success)
            //            {
            //                list.Add("DY-" + match.Value);
            //                functionIncompleteAdded = true; // 标记已添加
            //                break; // 每个detail只处理第一个匹配
            //            }
            //        }
            //    }
            //    else if (!containsFunctionIncomplete)
            //    {
            //        // 处理不包含"功能不全"的情况
            //        string pattern = @"K\d+-\d+-[A-Za-z]\d+";
            //        MatchCollection matches = Regex.Matches(detail.content, pattern);

            //        foreach (Match match in matches)
            //        {
            //            if (match.Success)
            //            {
            //                list.Add("DY-" + match.Value);
            //            }
            //        }
            //    }
            //}



           
            List<String> list = new List<string>();
            bool gMatch = false;//功能不全g只能出现一次
            foreach (var detail in details)
            {
                string pattern = @"K\d+-\d+-[A-Za-z]\d*";
                MatchCollection matches = Regex.Matches(detail.content, pattern);
                foreach (Match match in matches)
                {
                    if (match.Success)
                    {
                        list.Add("DY-" + match.Value);
                    }
                }
            }

            //var result = string.Join(",", list.Distinct());
            var result = string.Join(",", list);
            Console.WriteLine(result);

            List<int > ints = new List<int>();
            ints.Add(1);

            ints.Add(2);
            ints.Add(3);

            var data =  JsonConvert.SerializeObject(ints);
            Console.WriteLine(data);
        }
    }

    public class Detail
    {
        public string content { get; set; }

        public decimal? score { get; set; }

        public string detail { get; set; }
    }
}
